package com.bugsnag.ohos;

import java.util.Arrays;
import java.util.Optional;
import java.util.function.Predicate;

/**
 * ThreadSendPolicy
 *
 * @since 2021-07-01
 */
public enum ThreadSendPolicy {
    /**
     * Threads should be captured for all events.
     */
    ALWAYS,

    /**
     * Threads should be captured for unhandled events only.
     */
    UNHANDLED_ONLY,

    /**
     * Threads should never be captured.
     */
    NEVER;

    /**
     * generate ThreadSendPolicy
     *
     * @param str
     * @return ThreadSendPolicy
     */
    public static ThreadSendPolicy fromString(String str) {
        Optional<ThreadSendPolicy> sendPolicy = Arrays.stream(values()).filter(new Predicate<ThreadSendPolicy>() {
            @Override
            public boolean test(ThreadSendPolicy threadSendPolicy) {
                return threadSendPolicy.name().equals(str);
            }
        }).findAny();
        return sendPolicy.get() != null ? sendPolicy.get() : ALWAYS;
    }
}
